import { mapValues, without } from 'lodash-es'

export interface CommonDefaultProps  {
  actionType: string
  url: string

  height: string
  width: string
  margin: string,
  paddingLeft: string
  paddingRight: string
  paddingTop: string,
  paddingBottom: string

  borderStyle: string
  borderColor: string
  borderWidth: string
  borderRadius: string

  opacity: number
  // 阴影颜色
  boxShadowColor: string,
  // 必需的。水平阴影的位置。允许负值
  boxShadowHorizontal: string
  // 必需的。垂直阴影的位置。允许负值
  boxShadowVertical: string
  // 可选。模糊距离
  boxShadowBlur: string
  boxShadow: string

  position: string
  left: string
  top: string
  right: string

  cursor: string
  tag?: string
}

interface TextComponentProp {
  text: string
  fontSize: string
  fontFamily: string
  fontWeight: string
  fontStyle: string
  textDecoration:string
  lineHeight:string
  textAlign:string
  color: string
  backgroundColor: string
  // 首行缩进
  textIndent: string
}

export type TextComponentProps = TextComponentProp & CommonDefaultProps;

export const commonDefaultProps = {
  actionType: '',
  url: '',

  height: '',
  width: '',
  margin: '0',
  paddingLeft: '0px',
  paddingRight: '0px',
  paddingTop: '0px',
  paddingBottom: "0px",

  borderStyle: 'none',
  borderColor: 'transparent',
  borderWidth: '0px',
  borderRadius: '0',

  opacity: 1,
  boxShadowColor: 'transparent',
  boxShadowHorizontal: '0px',
  boxShadowVertical: '0px',
  boxShadowBlur: '0px',
  boxShadow: '0 0 0 rgb(0,0,0)',
  
  position: 'absolute',
  left: '0',
  top: '0',
  right: '0',

  cursor: ''
}

export const textDefaultProps = {
  text: '正文内容',
  fontSize: '14px',
  fontFamily: '',
  fontWeight: 'normal',
  fontStyle: "normal",
  textDecoration: 'none',
  lineHeight: '1',
  textAlign: 'left',
  color: 'rgb(0, 0, 0)',
  backgroundColor: '',
  textIndent: '',
  ...commonDefaultProps
}

export const textStylePropNames = without(Object.keys(textDefaultProps), 'actonType', 'url', 'text')
export const transformToComponentProps = <T extends { [key: string]: any }>(props: T) => {
  return mapValues(props, (item => {
    return {
      type: item.constructor,
      default: item
    }
  }))
}